package com.ost.kautilya.utils;

import java.util.HashMap;
import java.util.Map;

import com.ost.kautilya.utils.Metric.DataType;
import com.ost.kautilya.utils.metrics.AbstractMetric;

public class DistinctCount extends AbstractMetric<String> {
	Map<String, Boolean> map = new HashMap<String, Boolean>();

	public static class Node {
		public static final int CHARSET_SIZE = 127;
		private boolean endsHere = false;

		public static void main(String[] args) {/*
												 * String[] stra = {
												 * "siddharth", "ser", "", "",
												 * "", "", "", "", "", "" };
												 * Node root = new Node(); long
												 * count = 0; for (String st :
												 * stra) { Node n = root; FUNC:
												 * for (int i = 0; i <
												 * st.length(); i++) { int ci =
												 * (int) st.charAt(i); Node c =
												 * n.children.get(ci); if (c ==
												 * null) { count++; buildTree(n,
												 * st.toCharArray(), i); break
												 * FUNC; } else if (i ==
												 * st.length() - 1) { if
												 * (c.endsHere) { break FUNC; }
												 * else { count++; c.endsHere =
												 * true; } } else { n = c;
												 * continue; } } }
												 * System.out.println(count);
												 */
		}
	}

	private static final long serialVersionUID = 1L;

	protected DistinctCount(DataType dt) {
		super(dt);
	}

	@Override
	protected double asDouble() {
		return map.size();
	}

	@Override
	public Number value() {
		return map.size();
	}

	@Override
	public void push(long index, String st) {
		if (st != null && st.length() > 0) map.put(st, true);/*
						 * if (st == null) { return; } Node n = root; for (int i
						 * = 0; i < st.length(); i++) { int ci = (int)
						 * st.charAt(i); if (n.children.size() <= ci) {
						 * n.children.set(ci, null); } Node c =
						 * n.children.get(ci); if (c == null) { count++;
						 * buildTree(n, st.toCharArray(), i); break; } else if
						 * (i == st.length() - 1) { if (c.endsHere) { break; }
						 * else { count++; c.endsHere = true; } } else { n = c;
						 * continue; } }
						 */
	}

	private static void buildTree(Node n, char[] chars, int offset) {/*
																	 * for (int
																	 * i =
																	 * offset; i
																	 * <
																	 * chars.length
																	 * ; i++) {
																	 * n =
																	 * n.children
																	 * .
																	 * set((int)
																	 * chars[i],
																	 * new
																	 * Node());
																	 * }
																	 * n.endsHere
																	 * = true;
																	 */
	}

	@Override
	public void reset() {

	}

}
